//
//  BaseScrollViewManager.m
//  智云网校
//
//  Created by 毕武侠 on 2017/5/22.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "BaseScrollViewManager.h"

@interface BaseScrollViewManager ()

@property (nonatomic, strong) UIScrollView *view;
@property (nonatomic, strong, readwrite) RACSignal *scrollOffSignal;
@property (nonatomic, strong, readwrite) BaseModel *model;

@end

@implementation BaseScrollViewManager
@dynamic view;
@dynamic model;

- (instancetype)initWithView:(UIScrollView *)view ofIndex:(NSUInteger)index ofModel:(BaseModel *)model {
    self = [super init];
    if (self) {
        self.view = view;
        self.index = index;
        self.model = model;
        [self setupConfigure];
    }
    return self;
}

- (void)setupConfigure {
    self.view.pagingEnabled = YES;
    self.view.contentSize = CGSizeMake(SCREEN_WIDTH * self.index, self.view.height);
    
    self.scrollOffSignal = RACObserve(self.view, contentOffset);
}

- (void)setSelectSignal:(RACSignal *)selectSignal {
    _selectSignal = selectSignal;
    
    @weakify(self)
    [selectSignal subscribeNext:^(NSNumber *x) {
        @strongify(self)
        [self.view setContentOffset:CGPointMake([x integerValue] * SCREEN_WIDTH, 0) animated:YES];
    }];
}

@end
